<template>
    <div id="app" style="padding-left: 5px;padding-right: 5px">
        <p> 正在{{type}}.....</p>
        <a-progress :percent="percent" :status="status" :width="80"/>
        <br>
        <span>{{info.nowDes}}</span><br>
        <span>剩余项：{{info.fileNums-info.opNums}}/{{info.fileNums}}</span><br>
        <span>剩余大小：{{(info.countSize-info.opSize) | dataSize}}/{{info.countSize | dataSize }}</span><br>

        <div style="text-align: right">
            <a-button type="danger" size="small" style="" :loading="canleing" @click="canle">
                取消
            </a-button>
        </div>
    </div>
</template>

<script>
    import {dataSize} from "../../js/dataSize"

    export default {
        name: "App",
        data() {
            return {
                timer: null,
                info: {
                    fileNums: 0,
                    opNums: 0,
                    opSize: 0,
                    countSize: 0,
                    nowDes: "",
                },
                percent: 0,
                status: "active",
                type: "",
                taskId: "",
                canleing: false,
            }
        },
        filters: {
            dataSize
        },
        created() {
            this.type = window.windowApi.param.type;
            this.taskId = window.windowApi.param.taskId;
        },
        methods: {
            getInfo() {
                this.$axios.get("/desktop/file/task/" + window.windowApi.param.taskId).then((res) => {
                    this.info = res.data.data;
                    this.percent = this.toFixed();
                    if (this.info.endTime === 0) {
                        setTimeout(this.getInfo, 500);
                    } else {
                        window.windowApi.refreshDesktop();
                        window.windowApi.close();
                    }
                }).catch(err => {
                    this.status = "exception"
                })
            },
            toFixed() {
                try {
                    let num = this.info.opNums / this.info.fileNums;
                    return Math.floor(num * 100)
                } catch (e) {
                    console.log(e)
                    return 0;
                }
            },
            canle() {
                this.canleing = true;
                this.$axios.delete("/desktop/file/task/" + this.taskId).then(res => {
                    // this.info = res.data.data;
                    // this.percent = this.toFixed();
                })
            }
        },
        mounted() {
            console.log(window);
            console.log("window.windowApi", window.windowApi)
            console.log(window.windowApi.param)
            this.getInfo();
        }
    }
</script>

<style scoped>

</style>